﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;

class FlyItemManager
{
    public int NumFlyItmes { get { return m_FlyItems.Count; } }

    public static FlyItemManager Instance = new FlyItemManager();
    List<FlyItem> m_FlyItems = new List<FlyItem>();
    FlyItemManager()
    {
        SceneManager.sceneUnloaded += OnUnSceneLoaded;
    }
    public void AddFlyItem(FlyItem item)
    {
        m_FlyItems.Add(item);
    }
    public void RemoveFlyItem(FlyItem item)
    {
        m_FlyItems.Remove(item);
    }

    public List<ArmTarget> checkFlyItemsInRange(Vector3 position, float distance, string selfInfluence)
    {
        List<ArmTarget> targets = new List<ArmTarget>();
        for (int i=0; i<NumFlyItmes; ++i)
        {
            float resultDistance = (m_FlyItems[i].transform.position - position).magnitude;
            if (resultDistance < distance && 
                InfluenceMG.get().isHostile(selfInfluence, m_FlyItems[i].m_Influence))
            {
                ArmTarget target = new ArmTarget();
                target.Target = m_FlyItems[i].gameObject;
                target.Distance = resultDistance;
                target.Type = ArmTarget.TargetType.FLYITEM;
                targets.Add(target);
            }
        }
        return targets;
    }
    public void OnUnSceneLoaded(Scene scene)
    {
        m_FlyItems.Clear();
    }

}
